import 'package:flutter/material.dart';

class RadioDemo extends StatefulWidget {
  RadioDemo({Key key}) : super(key: key);
  @override
  _RadioDemoState createState() => _RadioDemoState();
}

class _RadioDemoState extends State<RadioDemo> {
  int _sex = 0;

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('RadioDemo'),
      ),
      body: Center(
          child: Column(
        children: [
          Radio(
              value: 0,
              groupValue: _sex,
              activeColor: Colors.red,
              onChanged: (v) {
                setState(() {
                  this._sex = v;
                });
              }),
          Radio(
              value: 1,
              groupValue: _sex,
              activeColor: Colors.red,
              onChanged: (v) {
                setState(() {
                  this._sex = v;
                });
              }),
          RadioListTile(
              title: Text('男1'),
              subtitle: Text('男2'),
              value: 0,
              groupValue: _sex,
              activeColor: Colors.red,
              secondary: Icon(Icons.pregnant_woman_outlined),
              onChanged: (v) {
                setState(() {
                  this._sex = v;
                });
              }),
          RadioListTile(
              title: Text('女1'),
              subtitle: Text('女2'),
              value: 1,
              groupValue: _sex,
              activeColor: Colors.red,
              secondary: Icon(Icons.dangerous),
              onChanged: (v) {
                setState(() {
                  this._sex = v;
                });
              }),
          Switch(
              value: this._sex == 0,
              onChanged: (v) {
                setState(() {
                  this._sex = v ? 0 : 1;
                });
              })
        ],
      )),
    );
  }
}
